/* This is a simple program that prints out the first
 * max fibonacci numbers, each number on a new line.
 * Uses ecrire() to write to the console and gets input using lire()
 */

#include "fibonacci.h"

void fibonacci(int max){

  int v1 = 0;
  int v2 = 1;
  char buffer[10];

  if(max < 1){
    ecrire("n must at least be 1\n");
    quitter(FAILURE);
  }

  ecrire(itoa(v1,buffer,10));
  ecrire("\n");
  ecrire(itoa(v2,buffer,10));
  ecrire("\n");

  while(v1+v2 <= max){
    ecrire(itoa(v1+v2,buffer,10));
    ecrire("\n");
    v2 += v1; //store the new fibonacci number
    v1 = v2 - v1;
  }
  ecrire("done.\n");
  quitter(SUCCESS);

}
